﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
create PROCEDURE [dbo].[proc_ERP_Change_GetApplyByID]
	@id INT
AS
BEGIN
	Select 
		edc.id,
		edc.Proposer,
		edc.ProposerName,
		CASE edc.ProposeTitle
			WHEN 90 THEN '其它'
			WHEN 6 THEN '资产管理'
			WHEN 5 THEN '报销管理'
			WHEN 4 THEN '成单变更'
			WHEN 3 THEN '非企成单'
			WHEN 2 THEN '非常规成单'
			WHEN 1 THEN '常规成单'
		END AS ProposeTitle,
		edc.PCompanyId,
		(select CompanyName from Company where id=edc.PCompanyId) as PCompanyName,
		edc.PDepartmentId,
		(select DName from Department where id= edc.PDepartmentId) as PDName,
		edc.ApplionTime,
		edc.BDetails,
		edc.ADetails,
		edc.CAuditPerson,
		(select ename from employee where username=edc.CAuditPerson) as CAuditPersonName,
		edc.CAudit,
		edc.CMemo,
		edc.CAuditTime,
		edc.FAuditPerson,
		(select ename from employee where username=edc.FAuditPerson) as FAuditPersonName,
		edc.FAudit,
		edc.FMemo,
		edc.FAuditTime,
		edc.JEditPerson,
		(select ename from employee where username=edc.JEditPerson) as JEditPersonName,
        edc.JEdit,
        edc.JMemo,
        edc.JEditTime,
		edc.[State],
		CASE edc.[State]
			WHEN 5 THEN '处理完毕'
			WHEN 4 THEN '等待技术人员处理'
			WHEN 3 THEN '等待财务审批'
			WHEN 2 THEN '等待经理/主管审批'
			WHEN 1 THEN '中止'
		END AS StateText
	FROM
		ERP_DataChange edc
	WHERE id = @id
END
